<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px; width: 100%">
    <el-col>
      <span>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDept">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="nodeData.id !== ''" @click.native="editDept">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="nodeData.id !== ''" @click.native="delDept">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDept } from '@/api/departments'
export default {
  props: {
    nodeData: {
      type: Object,
      required: true
    }
  },
  methods: {
    addDept() {
      console.log('点击新增')
      this.$emit('addDept', this.nodeData)
    },
    editDept() {
      // 其实跟新增一样, 也需要通知父页面, 也需要将自己的数据传递出去
      this.$emit('editDept', this.nodeData)
    },
    async delDept() {
      // 二次询问
      await this.$confirm('是否确认删除')
      // 发送请求
      await delDept(this.nodeData.id)
      // 提示用户
      this.$message.success('删除成功')
      // 加载数据
      this.$emit('reloadPage')
    }
  }
}
</script>

<style>

</style>
